package com.minshenglife.zanzan.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.minshenglife.zanzan.dao.KeywordDao;
import com.minshenglife.zanzan.entity.weixin.Keyword;
import com.minshenglife.zanzan.service.KeywordService;

/**
 * 微信关键词service
 * @author jianghaibo
 *
 */
@Component
@Transactional
public class KeywordServiceImpl implements KeywordService{

	@Resource
	KeywordDao keywordDao;

	@Override
	public List<Keyword> findAll() {
		return keywordDao.findByExample(new Keyword());
	}

	@Override
	public List<Keyword> findAllByAppid(String appid) {
		Keyword keyword = new Keyword();
		keyword.setAppid(appid);
		return keywordDao.findByExample(keyword);
	}

	@Override
	public Keyword add(Keyword keyword) {
		Long id = keywordDao.findMaxId();
		if(id != null){
			id += 1l;
		}else{
			id = 1l;
		}
		keyword.setId(id);
		keywordDao.add(keyword);
		return keyword;
	}

	@Override
	public boolean delete(Keyword keyword) {
		boolean flag = true;
		try {
			keywordDao.deleteByExample(keyword);
		} catch (Exception e) {
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}
}
